home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime vr / vrscript / feature files / vrpicture.c < prev    next >
Encoding:
Text File  |  2000-09-28  |  5.5 KB  |  183 lines

  1. //////////
  2. //
  3. //    File:        VRPicture.c
  4. //
  5. //    Contains:    Code for drawing pictures into the prescreen buffer.
  6. //
  7. //    Written by:    Tim Monroe
  8. //
  9. //    Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  10. //
  11. //    Change History (most recent first):
  12. //
  13. //       <5>         04/30/97    rtm        reworked semantics to be like sounds and movies
  14. //       <4>         03/10/97    rtm        copied file from VRLogo project and integrated with VRScript;
  15. //                                    removed support for object nodes
  16. //       <3>         02/21/97    rtm        worked around a QTVR bug by adding code to node-leaving proc
  17. //       <2>         02/14/97    rtm        added support for object nodes
  18. //       <1>         01/28/97    rtm        first file
  19. //    
  20. // This file contains routines for drawing a picture on top of a panorama.
  21. //
  22. //////////
  23.  
  24. // TO DO:
  25. // + drawing large PICTs into a small rectangle can be slow; 
  26. //   we should cache the small image for improved performance
  27. // + rework this to allow any kind of image file to be opened (using graphics importer routines)
  28.  
  29. // header files
  30. #include "VRPicture.h"
  31. #include "VRScript.h"
  32.  
  33.  
  34. //////////
  35. //
  36. // VRPicture_ShowPicture
  37. // Display a picture, or hide a displayed picture.
  38. //
  39. //////////
  40.  
  41. void VRPicture_ShowPicture (WindowObject theWindowObject, UInt32 theResID, UInt32 theEntryID, UInt32 theHeight, UInt32 theWidth, UInt32 thePegSides, UInt32 theOffset, UInt32 theOptions)
  42. {
  43.     ApplicationDataHdl        myAppData;
  44.     PicHandle                myHandle;
  45.     Boolean                    myNeedShowPicture = false;
  46.     Boolean                    myNeedPictureData = false;
  47.     VRScriptPicturePtr        myPointer = NULL;
  48.     
  49.     myAppData = (ApplicationDataHdl)GetAppDataFromWindowObject(theWindowObject);
  50.     if (myAppData == NULL)
  51.         return;
  52.     
  53.     // see if this picture is already in our list of displayed pictures                
  54.     myPointer = (VRScriptPicturePtr)VRScript_GetObjectByEntryID(theWindowObject, kVREntry_OverlayPicture, theEntryID);
  55.         
  56.     if (myPointer == NULL) {
  57.         // this picture isn't in our list yet, so we'll need to add it to the list
  58.         myNeedPictureData = true;
  59.         myNeedShowPicture = true;
  60.     } else {
  61.         // this picture is already in our list; theOptions determines how we handle this request:
  62.         
  63.         switch (theOptions) {
  64.         
  65.             case kVRMedia_TogglePause:
  66.             case kVRMedia_ToggleStop:
  67.             case kVRMedia_Stop:
  68.                 // stop displaying the picture
  69.                 myNeedShowPicture = false;
  70.                 myNeedPictureData = false;
  71.                 break;
  72.                 
  73.             case kVRMedia_PlayNew:
  74.             case kVRMedia_Restart:
  75.             case kVRMedia_Continue:
  76.             default:
  77.                 // show the specified picture
  78.                 myNeedShowPicture = true;
  79.                 myNeedPictureData = false;
  80.                 break;
  81.         }
  82.     }
  83.     
  84.     if (myNeedShowPicture) {
  85.         if (myNeedPictureData) {
  86.             myHandle = GetPicture((short)theResID);
  87.             if (myHandle != NULL)
  88.                 myPointer = VRScript_EnlistOverlayPicture(theWindowObject, theResID, theEntryID, theHeight, theWidth, thePegSides, theOffset, myHandle, theOptions);
  89.         }
  90.     } else {
  91.         if (myPointer != NULL) 
  92.             VRScript_DelistEntry(theWindowObject, (VRScriptGenericPtr)myPointer);
  93.     }
  94. }
  95.  
  96.  
  97. ///////////
  98. //
  99. // VRPicture_DrawNodePictures
  100. // Draw the selected picture into the prescreen buffer.
  101. //
  102. //////////
  103.  
  104. void VRPicture_DrawNodePictures (WindowObject theWindowObject)
  105. {
  106.     ApplicationDataHdl        myAppData;
  107.     VRScriptPicturePtr        myPointer;
  108.  
  109.     // get the application-specific data associated with the window
  110.     myAppData = (ApplicationDataHdl)GetAppDataFromWindowObject(theWindowObject);
  111.     if (myAppData == NULL)
  112.         return;
  113.     
  114.     // walk our linked list and draw any overlay pictures for this node
  115.     myPointer = (VRScriptPicturePtr)(**myAppData).fListArray[kVREntry_OverlayPicture];
  116.     while (myPointer != NULL) {
  117.         if (myPointer->fResourceData != NULL) {
  118.             Rect    myMovieRect;
  119.             Rect    myPictRect;
  120.  
  121.             // get the current size of the movie
  122.             GetMovieBox((**theWindowObject).fMovie, &myMovieRect);
  123.             
  124.             // set the size of the overlay rectangle
  125.             if ((myPointer->fBoxHeight == kVRUseMovieHeight) && (myPointer->fBoxWidth == kVRUseMovieWidth))
  126.                 MacSetRect(&myPictRect, myMovieRect.left, myMovieRect.top, myMovieRect.right, myMovieRect.bottom);
  127.             else
  128.                 MacSetRect(&myPictRect, 0, 0, (short)myPointer->fBoxWidth, (short)myPointer->fBoxHeight);
  129.                 
  130.             // by default, the picture is centered in the movie rectangle
  131.             MacOffsetRect(&myPictRect, ((myMovieRect.right - myMovieRect.left) - (myPictRect.right - myPictRect.left)) / 2, 
  132.                                     ((myMovieRect.bottom - myMovieRect.top) - (myPictRect.bottom - myPictRect.top)) / 2);
  133.             
  134.             // set the position of the overlay rectangle
  135.             if ((myPointer->fPegSides) & kPegSide_Left) {
  136.                 MacOffsetRect(&myPictRect, (short)myPointer->fOffset, 0);
  137.             } else if ((myPointer->fPegSides) & kPegSide_Right) {
  138.                 MacOffsetRect(&myPictRect, (myMovieRect.right - myMovieRect.left) - (myPictRect.right + myPointer->fOffset), 0);
  139.             }
  140.             
  141.             if ((myPointer->fPegSides) & kPegSide_Top) {
  142.                 MacOffsetRect(&myPictRect, 0, (short)myPointer->fOffset);
  143.             } else if ((myPointer->fPegSides) & kPegSide_Bottom) {
  144.                 MacOffsetRect(&myPictRect, 0, (myMovieRect.bottom - myMovieRect.top) - (myPictRect.bottom + (short)myPointer->fOffset));
  145.             }
  146.             
  147.             // draw the picture
  148.             DrawPicture(myPointer->fResourceData, &myPictRect);
  149.         }
  150.             
  151.         myPointer = myPointer->fNextEntry;
  152.     }
  153.  
  154.     return;
  155. }
  156.  
  157.  
  158. //////////
  159. //
  160. // VRPicture_DumpNodePictures
  161. // Get rid of any overlay pictures associated with the current node.
  162. //
  163. //////////
  164.  
  165. void VRPicture_DumpNodePictures (WindowObject theWindowObject)
  166. {
  167.     VRScript_DeleteListOfType(theWindowObject, kVREntry_OverlayPicture);
  168. }
  169.  
  170.  
  171. //////////
  172. //
  173. // VRPicture_DumpEntryMem
  174. // Release any memory associated with the specified list entry.
  175. //
  176. //////////
  177.  
  178. void VRPicture_DumpEntryMem (VRScriptPicturePtr theEntry)
  179. {
  180.     if (theEntry != NULL)
  181.         ReleaseResource((Handle)(theEntry->fResourceData));
  182. }
  183.